package com.imooc.exception;

import com.imooc.utils.IMOOCJSONResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @description: 自定义异常全局捕获
 * @author: Yz
 * @create: 2020-07-10 14:17
 **/
@RestControllerAdvice
public class CustomExceptionHandler {

    /**
     * 捕获上传文件过大500kb异常
     * @param ex
     * @return
     */
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public IMOOCJSONResult hanlderMaxUploadFile(MaxUploadSizeExceededException ex){
        return IMOOCJSONResult.errorMsg("文件上传大小不能超过500kb，请压缩图片或者降低图片质量，再上传");
    }
}
